﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;

namespace MillerApp.Silverlight.Converters
{
    public class BooleanToStringConverter : IValueConverter
    {
        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return string.Empty;
            }
            if (string.IsNullOrWhiteSpace(value.ToString()))
            {
                return string.Empty;
            }
            
            bool v = (bool)value;
            if (v)
            {
                return "是";
            }
            else
            {
                return "否";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return string.Empty;
            }
            string v = value.ToString();
            if (v == "是")
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        #endregion
    }
}
